package de.graph.common.impl;

import de.graph.common.Edge;
import de.graph.common.Vertex;
import de.graph.document.Document;

final class EdgeImpl extends ElementImpl implements Edge {

    private static final long serialVersionUID = -8864150614647555623L;

    protected static final String IS_DIRECTED = "isDirected";

    protected static final String TARGET = "target";

    protected static final String SOURCE = "source";

    protected EdgeImpl(final Document document) {
        super(document);
    }

    public Vertex getSourceVertex() {
        return getProperty(SOURCE);
    }

    public Vertex getTargetVertex() {
        return getProperty(TARGET);
    }

    public boolean isDirected() {
        return getProperty(IS_DIRECTED, true);
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();

        builder.append(getSourceVertex());
        if (isDirected()) {
            builder.append("--");
        }
        else {
            builder.append("<-");
        }
        builder.append(getLabel());
        builder.append("->");
        builder.append(getTargetVertex());

        return builder.toString();
    }
}
